package com.star.star.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.star.star.Activity.AidListActivity;
import com.star.star.Activity.circleActivity;
import com.star.star.Activity.helpActivity;
import com.star.star.Activity.tripActivity;
import com.star.star.R;
import com.star.star.adapter.aidAdapter;
import com.star.star.bean.abean;
import com.star.star.bean.aidBean;
import com.star.star.utils.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

import static androidx.recyclerview.widget.LinearLayoutManager.VERTICAL;

public class AidFragment extends Fragment implements View.OnClickListener {
    private LinearLayout ll_1, ll_2, ll_3, ll_4;
    private Banner fl_adbanner;
    private RecyclerView lv_chart;
    private Intent intent;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_aid, container, false);
        fl_adbanner = rootView.findViewById(R.id.fl_adbanner);
        initbanner();
        ll_1 = rootView.findViewById(R.id.ll_1);
        ll_2 = rootView.findViewById(R.id.ll_2);
        ll_3 = rootView.findViewById(R.id.ll_3);
        ll_4 = rootView.findViewById(R.id.ll_4);
        lv_chart = rootView.findViewById(R.id.lv_chart);
        ll_1.setOnClickListener(this);
        ll_2.setOnClickListener(this);
        ll_3.setOnClickListener(this);
        ll_4.setOnClickListener(this);
        initdata();
        return rootView;

    }

    @SuppressLint("WrongConstant")
    private void initdata() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(VERTICAL);
        lv_chart.setLayoutManager(layoutManager);
        List<abean> daBeans = new ArrayList<>();
        daBeans.add(new abean( "http://img4.imgtn.bdimg.com/it/u=1611985619,1261949322&fm=214&gp=0.jpg", "刘德华","99"));
        daBeans.add(new abean( "http://img2.imgtn.bdimg.com/it/u=2661081147,3253732559&fm=214&gp=0.jpg", "景天","97"));
        daBeans.add(new abean( "http://imgsrc.baidu.com/forum/w=580/sign=064bff0c2edda3cc0be4b82831e83905/6634037b02087bf447ac317af2d3572c10dfcf06.jpg", "涛涛","94"));
        aidAdapter adapte = new aidAdapter(getActivity(), daBeans);
        lv_chart.setAdapter(adapte);
        adapte.notifyDataSetChanged();
    }

    private void initbanner() {
        List<Integer> list  = new ArrayList<>();
        list.add(R.drawable.banner_1);
        list.add(R.drawable.banner_2);
        list.add(R.drawable.banner_3);
        fl_adbanner.setImages(list);
        fl_adbanner.setImageLoader(new GlideImageLoader("AidFragment"));
        fl_adbanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        fl_adbanner.setIndicatorGravity(BannerConfig.CENTER);
        fl_adbanner.startAutoPlay();
        fl_adbanner.start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_1://行程
                intent = new Intent(getActivity(), tripActivity.class);
                getActivity().startActivity(intent);
                break;
            case R.id.ll_2://圈子
                intent = new Intent(getActivity(), circleActivity.class);
                getActivity().startActivity(intent);
                break;
            case R.id.ll_3://应援
                 intent = new Intent(getActivity(), helpActivity.class);
                getActivity().startActivity(intent);
                break;
            case R.id.ll_4: //资讯
                 intent = new Intent(getActivity(), AidListActivity.class);
                getActivity().startActivity(intent);
                break;
        }
    }
}
